package com.heima.crm.common.utils;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.heima.crm.pojos.entity.TbClue;
import com.heima.crm.pojos.entity.TbUser;

import java.util.*;

public class CaptchaUtils {

    private final static Map<String, String> STRINGSTRINGMAP = Collections.synchronizedMap(new HashMap<String, String>());

    private final static Map<String, List<TbUser>> TEMPORARY_WAREHOUSE_USER = Collections.synchronizedMap(new HashMap<String, List<TbUser>>());

    private final static Map<String, List<TbClue>> TEMPORARY_WAREHOUSE_TBCLUE = Collections.synchronizedMap(new HashMap<String, List<TbClue>>());

    public static void set(String uuid, String captcha) {
        STRINGSTRINGMAP.put(uuid, captcha);
    }

    public static String get(String uid) {
        System.out.println(STRINGSTRINGMAP.get(uid));
        return STRINGSTRINGMAP.get(uid);
    }

    public static void clear(String uid) {
        STRINGSTRINGMAP.remove(uid);
    }

    public static  String temporarySetUser(List<TbUser> list) {
        String kid = UUID.randomUUID().toString();
        TEMPORARY_WAREHOUSE_USER.put(kid, list);
        return kid;
    }

    public static void removeTemporarySetUser(String kid) {
        TEMPORARY_WAREHOUSE_USER.remove(kid);
    }

    public static String temporaryInsertUser(String kid, BaseMapper<TbUser> mapper) {
        List<TbUser> items = TEMPORARY_WAREHOUSE_USER.get(kid);
        for (TbUser item : items) {
            mapper.insert(item);
        }
        return "ok";
    }


    public static  String temporarySetTbClue(List<TbClue> list) {
        String kid = UUID.randomUUID().toString();
        TEMPORARY_WAREHOUSE_TBCLUE.put(kid, list);
        return kid;
    }

    public static void removeTemporarySetTbClue(String kid) {
        TEMPORARY_WAREHOUSE_TBCLUE.remove(kid);
    }

    public static String temporaryInsertTbClue(String kid, BaseMapper<TbClue> mapper) {
        List<TbClue> items = TEMPORARY_WAREHOUSE_TBCLUE.get(kid);
        for (TbClue item : items) {
            mapper.insert(item);
        }
        return "ok";
    }




}
